#ifndef GLOBAL_PARAMETERS
#define GLOBAL_PARAMETERS

cbuffer PerFrameBuffer //: register( b0 )
{
	float4x4 Projection;	//: packoffset( c0 );
	float4x4 View;		//: packoffset( c1 );
	
	float3 CameraPos;
	float3 LightDirection;

	float4 LightColor;
	float3 AmbientColor;

	float A;
	float B; 
	float rhoOverPi;
};

/*float4x4 WVP;
float4x4 WV;
float4x4 WVInv;
*/
// map for depth checking
Texture2D DepthMap;

float windowHeight;
float windowWidth;

SamplerState DepthFilter
{
	Filter = ANISOTROPIC;
	AddressU = WRAP;
	AddressV = WRAP;
};

float GetDepth(float4 pixelPos){
	return saturate(pixelPos.z / pixelPos.w);
}

bool IsInFront(float4 pixelPos){
	float2 DepthTexC = float2(pixelPos.x / windowWidth, pixelPos.y / windowHeight);
    
    float shadowdepth = DepthMap.Sample(DepthFilter, DepthTexC ).r;    
	  
    // Check our value against the depth value
    float ourdepth = GetDepth(pixelPos);
    
    return shadowdepth-0.003f < ourdepth;
}

RasterizerState SOLID
{
	FillMode = Solid;
	CullMode = BACK;
	FrontCounterClockwise = false;

};

RasterizerState SURFEL
{
	FillMode = Solid;
	CullMode = BACK;
	FrontCounterClockwise = false;
};

RasterizerState OVERDRAW
{
	FillMode = Solid;
	CullMode = BACK;
};

RasterizerState SURFEL_DEPTH
{
	FillMode = Solid;
	CullMode = BACK;
	FrontCounterClockwise = false;
};

RasterizerState WF
{
	FillMode = Wireframe;
	CullMode = NONE;
	FrontCounterClockwise = false;
};

DepthStencilState DisableDepth
{
	DepthEnable = FALSE;
	DepthWriteMask = ZERO;
};

DepthStencilState EnableDepth
{
	DepthEnable = TRUE;	
	DepthWriteMask = ALL;
	DepthFunc = LESS;
};

DepthStencilState SamePlaneDepth
{
	DepthEnable = TRUE;	
	DepthWriteMask = ZERO;
};

BlendState NoAlphaBlending 
{ 
    AlphaToCoverageEnable = FALSE; 
    BlendEnable[0] = FALSE; 
}; 

BlendState AlphaBlending
{   
	AlphaToCoverageEnable = FALSE;
	SrcBlendAlpha = SRC_ALPHA;
	DestBlendAlpha = ZERO;
	BlendEnable[0] = FALSE;
	BlendOp = ADD;
	SrcBlend = SRC_ALPHA;
	DestBlend = ZERO;
	BlendOpAlpha = ADD;
	RenderTargetWriteMask[0] = 0x0F;	
};

BlendState OverDrawBlending
{   	
	AlphaToCoverageEnable = TRUE;

	BlendEnable[0] = TRUE;
	SrcBlend = SRC_ALPHA;
    DestBlend = INV_SRC_ALPHA;
    BlendOp = ADD;
    
    SrcBlendAlpha = SRC_ALPHA;
    DestBlendAlpha = INV_SRC_ALPHA;
	BlendOpAlpha = ADD;
	
    RenderTargetWriteMask[0] = 0x0F;

};


BlendState CrosshairAlphaBlending
{
    AlphaToCoverageEnable = FALSE;
    BlendEnable[0] = TRUE;
	SrcBlend = SRC_ALPHA;
	DestBlend = INV_SRC_ALPHA;
	//BlendOp = MAX;
	SrcBlendAlpha = SRC_ALPHA;
	DestBlendAlpha = INV_SRC_ALPHA;
	//BlendOpAlpha = MAX;
	RenderTargetWriteMask[0] = 0x0F;
};

#endif
